﻿using System;

using HsTec.Mobile.Green.BLL;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Data;

public partial class Benchmarking_BenchmarkingBManage : System.Web.UI.Page
{
    private BenchmarkBLL bll = new BenchmarkBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            try
            {
                Indicator.Text = Request.QueryString["sIndicator"].ToString();
            }
            catch
            {

            }
            GridView1.Attributes.Add("BorderColor", "LightSkyBlue");
            if (ViewState["sortDirection"] == null)
            {
                ViewState["sortDirection"] = " ASC";
            }
            if (ViewState["sortExpression"] == null)
            {
                ViewState["sortExpression"] = String.Empty;
            }
            this.sltAreaBind();
        }
    }

    private void sltAreaBind()
    {
        sltArea.DataTextField = "Name";
        sltArea.DataValueField = "ID";
        sltArea.DataSource = bll.GetAreaList();
        sltArea.DataBind();
        sltArea.Items.Insert(0, "请选择...");
        sltArea.Items[0].Value = "";
    }

    private string GetSearchString()
    {
        string searchStr = "(1=1)";

        string sddlRegionid = sltArea.SelectedValue.ToString().Trim();
        if (sddlRegionid != "")
        {
            searchStr += " and Area_ID  ='" + sddlRegionid + "' ";
        }
        searchStr += " and Years  ='" + sltYear.Value.Trim() + sltMonth.Value.Trim() + "'";
        return searchStr;
    }
    private void BindGridViewData()
    {
        string sErr = String.Empty;
        DataView mydv = bll.GetBenchmarkListB(sltYear.Value.Trim() + sltMonth.Value.Trim(), ref sErr);
        if (mydv == null)
        {
            Response.Write("<script language=javascript>alert('" + sErr + "');</script>");
            return;
        }
        else
        {
            GridView1.DataSource = mydv;
            GridView1.DataBind();
        }
    }
    /// <summary>
    /// 查询标杆值的相关参数 并显示在GridView中 用户通过文本框输入标杆值信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindGridViewData();
        //按各地市信息
        //5月单位业务量能耗占全年比例算法 = 2009年5月份/2009年全年单位业务量能耗
        //2009年全年单位业务量能耗 = 2009年全年单位业务量能耗*单位业务量能耗变化率
    }

    protected void btnAdd_ServerClick(object sender, EventArgs e)
    {
        Dictionary<string, string> dc = new Dictionary<string, string>();
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            HtmlInputText txtMark = (HtmlInputText)(GridView1.Rows[i].Cells[10].FindControl("txtMark"));
            dc.Add(GridView1.Rows[i].Cells[0].Text.ToString(), txtMark.Value);
        }
        int iBack = bll.SetBenchMark(dc, sltYear.Value.Trim() + sltMonth.Value.Trim());
        if (iBack == 1)
        {
            Response.Write("<script language=javascript>alert('保存成功！');</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('保存失败！');</script>");
        }
        BindGridViewData();
    }
    protected void btnExport_ServerClick(object sender, EventArgs e)
    {
    }
    protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            HtmlInputText sltType = (HtmlInputText)(e.Row.Cells[10].FindControl("txtMark"));
            if (e.Row.Cells[12].Text.Trim() == "" || e.Row.Cells[12].Text.Trim() == "&nbsp;")
                sltType.Value = e.Row.Cells[10].Text.Trim();
            else
                sltType.Value = e.Row.Cells[12].Text.Trim();
            //sltType.Attributes.Add("onchange", "sltChange(this.value," + lblValue.ClientID + ");");
        }
    }
    protected void GridView1_Sorting(object sender, System.Web.UI.WebControls.GridViewSortEventArgs e)
    {

    }
    protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
    {

    }
    protected void linkBtnGo_Click(object sender, EventArgs e)
    {

    }
}
